package com.example.message.controller;

import com.example.common.resp.ResponseData;
import com.example.message.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Author:   dgc
 * Date:     2020/8/7 11:53
 */
@Api(tags = "MessageController",description = "消息接口")
@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @ApiOperation(value = "发送消息")
    @PostMapping(value = "/send")
    public Object sendMessage(@RequestBody Map map){
        try {
            String msg = MapUtils.getString(map, "msg");
            Integer time = MapUtils.getInteger(map, "time");
            messageService.sendMessage(msg, time);
            return ResponseData.success();
        }catch (Exception e){
            return ResponseData.fail();
        }
    }

    @GetMapping(value = "/test")
    public Object test(){
        try{
            return ResponseData.success();
        }catch (Exception e){
            return ResponseData.fail();
        }
    }
}
